// 处理权限

// 1、前端路由，菜单的数据

let  menu  = [
    {
        label:"系统首页",
        key:"0-0",
        path:""
    },
    {
        label:"轮播图管理",
        key:"0-1",        
        children:[
            {
                label:"轮播图的列表",
                key:"0-1-0",
                path: "Banner",
                name: "Banner",
                component: () => import("../views/Banner/BannerList.vue"),
                
            }
        ]
    },
    {
        label:"产品管理",
        key:"0-2",        
        children:[
            {
                label:"产品列表",
                key:"0-2-0",
                path: "Pro",
                name: "Pro",
                component: () => import("../views/Pro.vue")                
            },
            {
                label:"秒杀列表",
                key:"0-2-1",
                path: "SecondsKill",
                name: "SecondsKill",
                component: () => import("../views/SecondsKill.vue"),                
            },
            {
                label:"推荐列表",
                key:"0-2-2",
                path: "Recommend",
                name: "Recommend",
                component: () => import("../views/Recommend.vue"),
              }
        ]
    }
]


// 1、得到该用户的权限：
// 如：
// checkedkeys: ["0-0", "0-2", "0-2-0", "0-2-1", "0-2-2"]

// 2、根据后端返回的权限，得到当前用户的菜单和路由配置

export function getMenu(checkedkeys){
    let result = [];
    menu.forEach(item=>{
        if(checkedkeys.includes(item.key)){
            result.push({...item});            
            if(item.children){
                let endItem = result[result.length-1].children=[];
                item.children.forEach(subItem=>{
                    if(checkedkeys.includes(subItem.key)){
                        endItem.push(subItem);
                    }
                })
            }            
        }
    })
    return result;
}

// console.log(getMenu(["0-0", "0-2", "0-2-0", "0-2-1", "0-2-2"]));



